Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config inheritance for personality field #169

Merged
merged 3 commits into from
Nov 26, 2024
Merged

Add config inheritance for personality field #169

merged 3 commits into from
Nov 26, 2024

Conversation

wjt
Copy link
Member

@wjt wjt commented Nov 21, 2024

It is often the case that we want to build an image which just applies a
few minor changes to an existing personality. For instance, the apps we
want for most Spanish images are the same, but we have a few
country-specific applications, and we often wish to build a sub-variant
for a partner or region of a particular country.

Currently we need to copy the full list of apps & settings from our
es.ini personality config into (for instance) es_MX.ini; and then again
from es_MX.ini into (e.g.) es_MX_aguascalientes.ini to add some
region-specific apps or resources

Implement a form of inheritance where (e.g.) building the es_MX
personality reads es.ini and es_MX.ini, in that order; and (e.g.)
building the es_MX_aguascalientes personality reads es.ini, es_MX.ini
and es_MX_aguascalientes.ini, again in that order. This matches the
convention that we have of naming personalities for the locale, and then
adding further underscore-separated suffixes for subvariants thereof.

This is only implemented for the personality field. This is where we do
most of our customisation and is the place where inheritance would be
most useful.

https://phabricator.endlessm.com/T34731

@wjt wjt force-pushed the T34731 branch 3 times, most recently from c569149 to 1c40da3 Compare November 22, 2024 15:23
run-build Show resolved Hide resolved
for value in self._get_attr_values(attr):
path = os.path.join(dir_path, attr, value + '.ini')
namespace = dir_ns + '_'.join((attr, value))
config_files.append((path, namespace))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a much nicer version of my idea for the last time this came up. See 3b3414c.

@dbnicholson
Copy link
Member

I'm all for this and make a quick attempt at this a while back that I never finished.

@wjt
Copy link
Member Author

wjt commented Nov 22, 2024

It turns out the hard parts are:

  • going through all the configs and updating them. Because this inheritance is implicit rather than explicit it's a flag day and everything has to be checked & updated. I'm nearly there, but...
  • making the list of kolibri channel IDs a merged list causes it to be sorted which I believe will actually affect the order the channels are presented in Kolibri in the image. Personally I don't care but I have some memory that it was deliberate and someone stopped me from sorting the channel IDs in the config for this reason.

@dbnicholson
Copy link
Member

It turns out the hard parts are:

  • going through all the configs and updating them. Because this inheritance is implicit rather than explicit it's a flag day and everything has to be checked & updated. I'm nearly there, but...

Yeah, that is probably very annoying. I don't envy you...

  • making the list of kolibri channel IDs a merged list causes it to be sorted which I believe will actually affect the order the channels are presented in Kolibri in the image. Personally I don't care but I have some memory that it was deliberate and someone stopped me from sorting the channel IDs in the config for this reason.

It is deliberate. Hmm, I think I have a solution for the sorted merge...

@dbnicholson
Copy link
Member

It is deliberate. Hmm, I think I have a solution for the sorted merge...

See #170.

It is often the case that we want to build an image which just applies a
few minor changes to an existing personality.  For instance, the apps we
want for most Spanish images are the same, but we have a few
country-specific applications, and we often wish to build a sub-variant
for a partner or region of a particular country.

Currently we need to copy the full list of apps & settings from our
es.ini personality config into (for instance) es_MX.ini; and then again
from es_MX.ini into (e.g.) es_MX_aguascalientes.ini to add some
region-specific apps or resources

Implement a form of inheritance where (e.g.) building the es_MX
personality reads es.ini and es_MX.ini, in that order; and (e.g.)
building the es_MX_aguascalientes personality reads es.ini, es_MX.ini
and es_MX_aguascalientes.ini, again in that order.  This matches the
convention that we have of naming personalities for the locale, and then
adding further underscore-separated suffixes for subvariants thereof.

This is only implemented for the personality field. This is where we do
most of our customisation and is the place where inheritance would be
most useful.

https://phabricator.endlessm.com/T34731
@wjt wjt marked this pull request as ready for review November 26, 2024 14:54
@wjt wjt changed the title WIP: Add underscore-separated config inheritence Add config inheritance for personality field Nov 26, 2024
wjt added 2 commits November 26, 2024 14:59
Now that we have inheritance in personality configs, it becomes useful
to be able to say that (for example) es_MX should add 1 specific channel
to the selection inherited from es.

Since commit 59980bc, values in merged fields keep the order in which
they were first encountered. As a result, if (for example) the es
personality specifies channels B, D, C (in that order) and es_MX adds
channel A, then the resulting order is B, D, C, A. The order is
significant: it is the order that channels are shown in the Kolibri
Learn tab. So in this case it is not possible to move channel A to the
top of the list without overriding the whole list of channels (which is
possible but loses the benefit of this change). In practice, I only
found two cases where this happens; in one case I hardcoded the previous
order, and in the other case I just accepted the slight change.

https://phabricator.endlessm.com/T34731
For projects in Haiti we have a (private) fr_HT personality.

Checking our metrics, the majority of fr activations are in metropolitan
France (the hexagonal bit of France that is just across the channel from
the UK, rather than overseas regions).
Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a winner!

ini_name = (value1 + '-' + value2 + '.ini')
path = os.path.join(dir_path, attr1 + '-' + attr2, ini_name)
namespace = (dir_ns +
'_'.join((attr1, attr2, value1, value2)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, string joins with +. Older Dan is ashamed of younger Dan.

@dbnicholson dbnicholson merged commit d12b666 into master Nov 26, 2024
2 checks passed
@dbnicholson dbnicholson deleted the T34731 branch November 26, 2024 21:55
wjt added a commit that referenced this pull request Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants